Skip to content

Add SonarAnalyzer.CSharp and tighten Roslyn analyzer rules - #1482

Merged
tillig merged 25 commits into
developfrom
feature/tighten-analyzers
May 29, 2026
Merged

Add SonarAnalyzer.CSharp and tighten Roslyn analyzer rules#1482
tillig merged 25 commits into
developfrom
feature/tighten-analyzers

Conversation

@tillig

@tillig tillig commented May 29, 2026

Copy link
Copy Markdown
Member

Summary

  • Adds SonarAnalyzer.CSharp (10.27.0.140913) to all projects
  • Introduces unified build/Source.ruleset and build/Test.ruleset with consistent analyzer configuration
  • Fixes all actionable analyzer warnings (code changes per-rule in individual commits)
  • Disables rules that are false positives or inapplicable for this project's patterns

Changes

  • New analyzer: SonarAnalyzer.CSharp added via PackageReference with PrivateAssets=all
  • Rulesets: Unified Source.ruleset and Test.ruleset covering Microsoft, Sonar, StyleCop, and xUnit analyzers
  • Code fixes: Various warning fixes committed individually by rule ID for easy review
  • Zero warnings: Build completes with no analyzer warnings

Test plan

  • CI build passes (zero errors, zero warnings)
  • All existing tests pass
  • No public API changes (verify with dotnet format --verify-no-changes)

tillig added 25 commits May 28, 2026 10:23
Adds SonarAnalyzer.CSharp 10.27.0.140913 to all projects. Updates
Source.ruleset and Test.ruleset with comprehensive Sonar rule
configuration. Fixes all test analyzer warnings with actual code
changes rather than suppressions.
… classes.

Replaces the [SuppressMessage] for CA1018 with an actual [AttributeUsage]
declaration, which also resolves the Sonar S3993 warning about specifying
AttributeUsage on derived types for readability.
Autofac intentionally maintains deprecated APIs for backward compatibility.
Tests exercise deprecated APIs to verify they still work. Warnings about
using deprecated code are not actionable in this context.
- CA1063 (Implement IDisposable correctly): enabled as Warning in both
  Source and Test rulesets for explicit enforcement.
- S3881 (IDisposable pattern): disabled because Autofac uses non-standard
  dispose patterns for container lifecycle management.
- Fixed comment/rule ordering where S1133 insertion displaced comments.
- CA1711: test classes commonly use suffixes like Impl, Handler, etc.
- CA1721: test interfaces intentionally have properties matching methods.
- S125: commented-out code in tests is acceptable for examples/notes.
@codecov

codecov Bot commented May 29, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 81.30081% with 69 lines in your changes missing coverage. Please review.
✅ Project coverage is 77.77%. Comparing base (b0d4b65) to head (9872113).

Files with missing lines Patch % Lines
.../Core/Resolving/Pipeline/ResolvePipelineBuilder.cs 70.83% 20 Missing and 8 partials ⚠️
.../Core/Activators/Reflection/ReflectionActivator.cs 91.15% 6 Missing and 7 partials ⚠️
...atures/Collections/CollectionRegistrationSource.cs 76.66% 5 Missing and 2 partials ⚠️
...ofac/Core/Registration/ComponentRegistryBuilder.cs 14.28% 6 Missing ⚠️
src/Autofac/RegistrationExtensions.Decorators.cs 14.28% 3 Missing and 3 partials ⚠️
...ilder{TLimit,TActivatorData,TRegistrationStyle}.cs 0.00% 0 Missing and 2 partials ⚠️
...ctivators/Reflection/AutowiringPropertyInjector.cs 87.50% 1 Missing and 1 partial ⚠️
src/Autofac/RegistrationExtensions.cs 50.00% 1 Missing and 1 partial ⚠️
src/Autofac/Core/ActivatingEventArgs.cs 0.00% 0 Missing and 1 partial ⚠️
src/Autofac/Util/FallbackDictionary.cs 0.00% 0 Missing and 1 partial ⚠️
... and 1 more
Additional details and impacted files
@@             Coverage Diff             @@
##           develop    #1482      +/-   ##
===========================================
+ Coverage    77.24%   77.77%   +0.52%     
===========================================
  Files          217      217              
  Lines         5806     5827      +21     
  Branches      1250     1252       +2     
===========================================
+ Hits          4485     4532      +47     
+ Misses         791      759      -32     
- Partials       530      536       +6     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@tillig
tillig merged commit f6c1e8b into develop May 29, 2026
10 checks passed
@tillig
tillig deleted the feature/tighten-analyzers branch May 29, 2026 21:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant